// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Limit.java

package com.oa.flow;

import com.oa.database.*;
import com.oa.sysmanage.Position;
import com.oa.util.Format;
import java.io.PrintStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;

// Referenced classes of package com.oa.flow:
//            LimitInfor

public class Limit
{

    private DataConn dataConn;
    private QueryData queryData;
    private InsertData insertData;
    private Format format;
    private ResultSet rs;
    private PreparedStatement pstmt;
    private String sTable;
    private String sField;
    private String sCond;
    private String sql;
    private int iErrorCode;
    private LimitInfor limitInfor;
    private ArrayList positionList;
    private String positionStr;
    private ArrayList userList;
    private String userStr;

    public Limit()
    {
        dataConn = null;
        queryData = null;
        insertData = null;
        format = null;
        rs = null;
        pstmt = null;
        sTable = "";
        sField = "";
        sCond = "";
        sql = "";
        iErrorCode = 0;
        limitInfor = null;
        positionList = null;
        positionStr = null;
        userList = null;
        userStr = null;
    }

    public Limit(DataConn dataConnection)
    {
        dataConn = null;
        queryData = null;
        insertData = null;
        format = null;
        rs = null;
        pstmt = null;
        sTable = "";
        sField = "";
        sCond = "";
        sql = "";
        iErrorCode = 0;
        limitInfor = null;
        positionList = null;
        positionStr = null;
        userList = null;
        userStr = null;
        dataConn = dataConnection;
        format = new Format();
    }

    public String getPositionStr()
    {
        return positionStr;
    }

    public Collection getLimitedPosition()
        throws Exception
    {
        try
        {
            sql = "select XZBXZW from OA_GYLC_RYXZ  Where XZBXZW>0 group by XZBXZW";
            pstmt = dataConn.getConnection().prepareStatement(sql);
            rs = pstmt.executeQuery();
            String temp = "0";
            positionStr = "0";
            positionList = new ArrayList();
            for(; rs.next(); positionList.add(temp))
            {
                temp = format.toSpaceStr(rs.getString("XZBXZW"));
                positionStr += "," + temp;
            }

            pstmt.close();
        }
        catch(Exception e)
        {
            throw e;
        }
        return positionList;
    }

    public Collection getVisitPosition(int iUserId)
        throws Exception
    {
        String userid = Integer.toString(iUserId);
        Position position = new Position(dataConn);
        String strPosition = position.getYGZW(userid);
        try
        {
            sql = " select XZBXZW FROM OA_GYLC_RYXZ  where ((XZRY>0 and XZRY = " + userid + ") " + "  or    (XZZW>0 and XZZW in (" + strPosition + "))) " + " group by XZBXZW ";
            pstmt = dataConn.getConnection().prepareStatement(sql);
            rs = pstmt.executeQuery();
            String temp = "0";
            positionStr = "0";
            positionList = new ArrayList();
            for(; rs.next(); positionList.add(temp))
            {
                temp = format.toSpaceStr(rs.getString("XZBXZW"));
                positionStr += "," + temp;
            }

            pstmt.close();
        }
        catch(Exception e)
        {
            throw e;
        }
        return positionList;
    }

    public LimitInfor getLimitedInfor(int iPosition)
        throws Exception
    {
        String sYGID;
        String sZWID;
        boolean flag;
        String positionName = "";
        String sYGXM = "";
        String sZWMC = "";
        sYGID = "0";
        sZWID = "0";
        String temp = "0";
        flag = false;
        sql = " select XZRY,XZZW FROM OA_GYLC_RYXZ  where XZBXZW=" + iPosition;
        pstmt = dataConn.getConnection().prepareStatement(sql);
        for(rs = pstmt.executeQuery(); rs.next();)
        {
             temp = rs.getString("XZRY");
            if(!temp.equals("0"))
                sYGID = sYGID + "," + temp;
            temp = rs.getString("XZZW");
            if(!temp.equals("0"))
                sZWID = sZWID + "," + temp;
            flag = true;
        }

        pstmt.close();
        if(!flag)
            return null;
        try
        {
            QueryData queryData = new QueryData(dataConn);
             positionName = queryData.getYGZW_array(Integer.toString(iPosition));
            iErrorCode = queryData.getErrorCode();
            if(iErrorCode != 0)
                System.out.print(queryData.getErrorMessage());
             sYGXM = queryData.getYGXM_array(sYGID);
            iErrorCode = queryData.getErrorCode();
            if(iErrorCode != 0)
                System.out.print(queryData.getErrorMessage());
            sZWMC = queryData.getYGZW_array(sZWID);
            iErrorCode = queryData.getErrorCode();
            if(iErrorCode != 0)
                System.out.print(queryData.getErrorMessage());
            limitInfor = new LimitInfor();
            limitInfor.setPositionId(iPosition);
            limitInfor.setPositionName(positionName);
            limitInfor.setStrYGID(sYGID);
            limitInfor.setStrYGXM(sYGXM);
            limitInfor.setStrZWID(sZWID);
            limitInfor.setStrZWMC(sZWMC);
        }
        catch(Exception e)
        {
            throw e;
        }
        return limitInfor;
    }

    public boolean deleteLimited(String strPosition)
    {
        sTable = "OA_GYLC_RYXZ";
        sCond = "XZBXZW in (" + strPosition + ")";
        DeleteData deleteData = new DeleteData(dataConn);
        iErrorCode = deleteData.delete(sTable, sCond);
        if(iErrorCode != 0)
        {
            System.out.println(deleteData.getErrorMessage());
            return false;
        } else
        {
            return true;
        }
    }

    public boolean deletePosition(String strPosition)
    {
        sTable = "OA_GYLC_RYXZ";
        sCond = "XZBXZW in (" + strPosition + ") or XZZW in (" + strPosition + ")";
        DeleteData deleteData = new DeleteData(dataConn);
        iErrorCode = deleteData.delete(sTable, sCond);
        if(iErrorCode != 0)
        {
            System.out.println(deleteData.getErrorMessage());
            return false;
        } else
        {
            return true;
        }
    }

    public boolean deleteUser(String strUser)
    {
        sTable = "OA_GYLC_RYXZ";
        sCond = "XZRY in (" + strUser + ")";
        DeleteData deleteData = new DeleteData(dataConn);
        iErrorCode = deleteData.delete(sTable, sCond);
        if(iErrorCode != 0)
        {
            System.out.println(deleteData.getErrorMessage());
            return false;
        } else
        {
            return true;
        }
    }

    public boolean addLimited(int iPosition, String strYGID[], String strZWID[])
        throws Exception
    {
        if(iPosition <= 0)
            return false;
        try
        {
            deleteLimited(Integer.toString(iPosition));
            int iLen_YGID = 0;
            if(strYGID != null)
                iLen_YGID = strYGID.length;
            int iLen_ZWID = 0;
            if(strZWID != null)
                iLen_ZWID = strZWID.length;
            int iLen = iLen_YGID;
            if(iLen > iLen_ZWID)
                iLen = iLen_ZWID;
            sql = " insert into OA_GYLC_RYXZ (XZBXZW,XZRY,XZZW)  values (?,?,?) ";
            pstmt = dataConn.getConnection().prepareStatement(sql);
            int i = 0;
            int iYGID = 0;
            int iZWID = 0;
            for(i = 0; i < iLen; i++)
            {
                iYGID = Integer.parseInt(strYGID[i]);
                iZWID = Integer.parseInt(strZWID[i]);
                if(iYGID > 0 || iZWID > 0)
                {
                    pstmt.setInt(1, iPosition);
                    pstmt.setInt(2, iYGID);
                    pstmt.setInt(3, iZWID);
                    pstmt.executeUpdate();
                }
            }

            if(iLen_YGID < iLen_ZWID)
                for(i = iLen; i < iLen_ZWID; i++)
                {
                    iYGID = 0;
                    iZWID = Integer.parseInt(strZWID[i]);
                    if(iYGID > 0 || iZWID > 0)
                    {
                        pstmt.setInt(1, iPosition);
                        pstmt.setInt(2, iYGID);
                        pstmt.setInt(3, iZWID);
                        pstmt.executeUpdate();
                    }
                }

            else
            if(iLen_YGID > iLen_ZWID)
                for(i = iLen; i < iLen_YGID; i++)
                {
                    iYGID = Integer.parseInt(strYGID[i]);
                    iZWID = 0;
                    if(iYGID > 0 || iZWID > 0)
                    {
                        pstmt.setInt(1, iPosition);
                        pstmt.setInt(2, iYGID);
                        pstmt.setInt(3, 0);
                        pstmt.executeUpdate();
                    }
                }

            pstmt.close();
        }
        catch(Exception e)
        {
            throw e;
        }
        return true;
    }

    public static void main(String args[])
    {
        DataConn dataConn = new DataConn();
        DataConn dataConn2 = new DataConn();
        Limit limit = new Limit(dataConn);
        LimitInfor limitInfor = null;
        try
        {
            int iPositionId = 135;
            String strYGID[] = {
                "40", "42", "50", "44"
            };
            String strZWID[] = {
                "114", "115", "117", "108"
            };
            limit.addLimited(iPositionId, strYGID, strZWID);
        }
        catch(Exception exception) { }
        dataConn.close();
        dataConn2.close();
    }
}
